<template>
  <div id="app" ref="app">
    <router-view></router-view>
  </div>
</template>
<script>
import '@/assets/css/flex.less';
import '@/assets/css/public.less';
import { mapActions, mapState } from 'vuex';
export default {
  name: 'App',
  data() {
    return {
      screenWidth:
        document.body.clientWidth || document.documentElement.clientWidth,
      timer: null,
    };
  },
  computed: {
    ...mapState(['globalConfig', 'appClassName', 'userInfo']),
  },
  watch: {
    screenWidth(val) {
      if (!this.timer) {
        this.screenWidth = val;
        this.timer = true;
        let that = this;
        setTimeout(function () {
          that.setRem();
          that.timer = false;
        }, 400);
      }
    },
  },
  mounted() {
    const that = this;
    window.onresize = () => {
      return (() => {
        window.screenWidth =
          document.body.clientWidth || document.documentElement.clientWidth;
        that.screenWidth = window.screenWidth;
        setTimeout(() => {
          this.setRem();
        }, 500);
      })();
    };
    this.$nextTick(() => {
      this.setRem();
    });
  },
  methods: {
    ...mapActions(['ON_APPCLASSNAME', 'onSend']),
    setRem() {
      let htmlDom = document.getElementsByTagName('html')[0];
      if (this.screenWidth > 768) {
        this.$refs.app.className = 'PC';
        htmlDom.style.fontSize = '75px';
        this.ON_APPCLASSNAME(true);
      } else {
        this.$refs.app.className = 'M';
        htmlDom.style.fontSize = '75px';
        this.ON_APPCLASSNAME(false);
      }
    },
  },
};
</script>
<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
